package com.aliyun.cloudcallcenter.crm.aliyun.manager.impl;

import com.aliyun.cloudcallcenter.crm.aliyun.manager.UserManager;
import com.aliyun.cloudcallcenter.crm.model.User;
import com.aliyun.cloudcallcenter.crm.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author edward
 * @date 2017/11/12
 */
@Service
public class UserManagerImpl implements UserManager {

    private static final Logger logger = LoggerFactory.getLogger(UserManagerImpl.class);

    @Autowired
    private UserRepository userRepository;

    @Override
    public User findByUserName(String userName) {
        return userRepository.findByUserName(userName);
    }

    @Override
    public User updateAkSkByUserName(String userName, String ak, String sk) {
        User user = userRepository.findByUserName(userName);
        user.setAk(ak);
        user.setSk(sk);
        user = userRepository.saveAndFlush(user);
        return user;
    }

    @Override
    public User addUser(User user) {
        return userRepository.save(user);
    }

    @Override
    public List<User> findAll() {
        return userRepository.findAll();
    }
}
